<?php
/*
  功能：抽奖活动表 model
  作者：cxm
  时间：2019-10-23
*/

namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;

class Activity extends BaseModel {
    use SoftDeletes;
    protected $dates = ['deleted_at']; //开启deleted_at
    protected $table='activity';  //绑定表

    /**
     * 奖品
     */
    public function goods(){
        return $this->hasMany(AwardGoods::class,'activity_id','id');
    }

    /**
     * 结束活动
     * @param $activity_id
     * @return mixed
     */
    public static function end($activity_id){
        return self::where('id',$activity_id)->update(['status'=>2]);
    }

    /**
     * 图片
     */
    public function file(){
        return $this->hasOne(File::class,'id','image');
    }

}